package com.gsj.maintain.controller;

import com.gsj.common.pojo.R;
import com.gsj.maintain.pojo.entity.TabMtRecord;
import com.gsj.maintain.pojo.entity.TabMtShop;
import com.gsj.maintain.pojo.vo.MtRecordVo;
import com.gsj.maintain.service.MtRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: clms-nine
 * @description: 维修记录控制层
 * @author: 郭书江
 * @create: 2021-07-23 14:43
 **/
@RestController
@RequestMapping("/maintain/record")
@Api(value = "/maintain/record")
public class MtRecordController {

    @Autowired
    private MtRecordService recordService;



    //查询维修记录单表分页
    @ApiOperation(value = "查询维修记录单表分页",httpMethod = "POST")
    @PostMapping("initMtRecordTable/{currentPage}/{pageSize}")
    public R initMtRecordTable(@PathVariable("currentPage")Integer currentPage,
                               @PathVariable("pageSize")Integer pageSize,
                               @RequestBody MtRecordVo mtRecordVo){
        return recordService.findMtRecordByPage(currentPage, pageSize, mtRecordVo);
    }

    //点修改时根据id回显数据
    @ApiOperation(value = "点修改时根据id回显数据",httpMethod = "GET")
    @GetMapping("selById/{id}")
    public R selById(@ApiParam(value = "类型主键ID") @PathVariable("id") Integer id){
        return recordService.selById(id);
    }
    //删除
    @ApiOperation(value = "删除",httpMethod = "DELETE")
    @DeleteMapping("del/{id}")
    public R del(@ApiParam(value = "类型主键ID") @PathVariable("id") Integer id){
        return recordService.del(id);
    }
    //添加维修厂
    @ApiOperation(value = "添加维修厂",httpMethod = "POST")
    @PostMapping("insertMtRecord/{username}")
    public R insertMtShop(@ApiParam(value = "TabMtRecord实体类") @RequestBody TabMtRecord mtRecord,
                          @ApiParam(value = "操作人name ") @PathVariable("username") String username){
        return recordService.insert(mtRecord,username);
    }
    //根据id修改维修厂信息
    @ApiOperation(value = "根据id修改信息",httpMethod = "PUT")
    @PutMapping("updateMtRecordById")
    public R update(@ApiParam(value = "TabMtRecord实体类") @RequestBody TabMtRecord mtRecord){
        return recordService.up(mtRecord);
    }

    //查询汽车给添加维修记录使用作为下拉框
    @ApiOperation(value = "查询汽车给添加维修记录使用作为下拉框",httpMethod = "GET")
    @GetMapping("selectListAll")
    public R selById(){
        return recordService.selectCarListAll();
    }

//根据id查询车辆是否在维修中
    @ApiOperation(value = "根据id查询车辆是否在维修中",httpMethod = "GET")
    @GetMapping("getCarById/{id}")
    public R getCarById(@PathVariable("id")Integer id){
        System.out.println(id);
            return recordService.getCarById(id);
    }

    //名称校验
    @ApiOperation(value = "汽车id校验",httpMethod = "POST")
    @PostMapping("selMtRecordCarId")
    public R selUserName(@ApiParam(value = "TabMtRecord实体类")
                         @RequestBody TabMtRecord mtRecord){
        return recordService.selMtRecordCarId(mtRecord);
    }
}
